package com.beaven.imclient.data;

import com.beaven.imclient.adapter.UserAdapter;
import com.beaven.model.data.helper.UserHelper;
import com.beaven.model.model.db.Category;
import com.beaven.model.model.db.Group;
import com.chad.library.adapter.base.entity.AbstractExpandableItem;
import com.chad.library.adapter.base.entity.MultiItemEntity;

/**
 * author: Beaven
 * time: 2017/5/26 18:27
 */

public class ItemCategory extends AbstractExpandableItem<ItemUser> implements MultiItemEntity {

  private String id;
  private String name;
  private String status;
  private int type;
  private boolean isExpand;

  public ItemCategory(String id, String name, String status, int type, boolean isExpanded) {
    this.id = id;
    this.name = name;
    this.status = status;
    this.type = type;
    this.isExpand = isExpanded;
  }

  public void setStatus(String status) {
    this.status = status;
  }

  public boolean isExpand() {
    return isExpand;
  }

  public void setExpand(boolean expand) {
    isExpand = expand;
    if (this.type == UserAdapter.TYPE_CATEGORY) {
      Category category = UserHelper.findCategory(this.id);
      category.setExpanded(expand);
      category.update();
    }
  }

  public String getId() {
    return id;
  }

  public int getType() {
    return type;
  }

  public String getName() {
    return name;
  }

  public String getStatus() {
    return status;
  }

  @Override public int getLevel() {
    return 1;
  }

  @Override public int getItemType() {
    return UserAdapter.TYPE_CATEGORY;
  }

  @Override public String toString() {
    return "ItemCategory{"
        + "id='"
        + id
        + '\''
        + ", name='"
        + name
        + '\''
        + ", status='"
        + status
        + '\''
        + ", type="
        + type
        + '}';
  }

  public static ItemCategory build(Category cate) {
    return new ItemCategory(cate.getId(), cate.getName(), "", UserAdapter.TYPE_CATEGORY,
        cate.isExpanded());
  }

  public static ItemCategory build(Group group) {
    return new ItemCategory(group.getId(), group.getName(), "", UserAdapter.TYPE_GROUP, false);
  }
}